var backupResults = {
	win : null,
	isDownload : null,
	init : function(btnId){
		this.isDownload = (btnId == 'btnDownloadDB');		
		if(this.win == null){
			style = 'style = "'+
			'padding : 5px 0px 5px 20px;'+
			'background-repeat : no-repeat;'+
			'background-position-y : 4px "';
			html = '<div id="db_backup_txt1" '+ style +'></div>';			
			html+= '<div id="db_backup_txt2" '+ style +'></div>';
			this.win = new Ext.Window({
				width:325,
		        height:130,	
		        modal: true,
		        closable:true,
		        closeAction:'hide',
		        resizable   : false,
        		draggable   : false,
        		closable:false,	
		        plain: true,
		        title: 'Database Backup',
		        bodyStyle: 'padding:5px 10px 20px 10px;',
		        html: html,
		        buttonAlign : 'center',
		        buttons:[{
					handler: function(){
						backupResults.win.hide();
						if(	backupResults.firstActionOK &&
							backupResults.secondActionOK &&
							backupResults.isDownload
						){
							config.logOut();														
						}
					}
		        }]
			});	
		}		
		this.win.show();
		txt1 = this.isDownload?
			'Descargando Backup desde su cuenta Dropbox':
			'Generando archivo Backup de la base de datos';
		txt2 = this.isDownload?
			'Restaurando base de datos desde el archivo de Backup':
			'Subiendo archivo Backup a su cuenta Dropbox';
		imgBackground = {
			'background-image':'url('+config.img.loginDropbox.getLoading()+')'
		};
		Ext.select('#db_backup_txt1').update(txt1);
		Ext.select('#db_backup_txt2').update(txt2);
		Ext.select('#db_backup_txt1').setStyle(imgBackground);
		Ext.select('#db_backup_txt2').setStyle(imgBackground);
		this.win.buttons[0].disable();
		this.win.buttons[0].setText('Trabajando...');
		this.ajaxConfig.action = this.isDownload?
			'download_Dropbox_dbFile':
			'backup_database_toFile';
		config.ajax.init(this.ajaxConfig,this.ajaxSuccess,this.ajaxFail);		
	},
	ajaxConfig : {
		action: null
	},
	firstActionOK : false,
	secondActionOK : false,
	ajaxSuccess : function(jsonData){
		Ext.select('#db_backup_txt1').setStyle({
			'background-image':'url('+config.img.loginDropbox.getCheck()+')'
		});
		backupResults.firstActionOK = true;
		backupResults.ajaxConfig.action = backupResults.isDownload?
			'restore_database_fromFile':
			'upload_dropbox_dbfile';
		config.ajax.init(
			backupResults.ajaxConfig,
			backupResults.ajaxSuccessAction2,
			backupResults.ajaxFail
		);	
	},
	ajaxFail : function(){
		backupResults.win.buttons[0].enable();
		backupResults.win.buttons[0].setText('Abortar');
		if(!backupResults.firstActionOK){
			Ext.select('#db_backup_txt1').setStyle({
				'background-image':'url('+config.img.loginDropbox.getError()+')'
			});
		}
		Ext.select('#db_backup_txt2').setStyle({
			'background-image':'url('+config.img.loginDropbox.getError()+')'
		});
	},
	ajaxSuccessAction2 : function(jsonData){
		Ext.select('#db_backup_txt2').setStyle({
			'background-image':'url('+config.img.loginDropbox.getCheck()+')'
		});
		backupResults.secondActionOK = true;
		backupResults.win.buttons[0].enable();
		backupResults.win.buttons[0].setText(backupResults.isDownload?'Reiniciar':'Listo');			
	}
};